package com.ustcinfo.study.hbase.xngroup.liuqiang;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.ustcinfo.ishare.bdp.hbase.HBaseOperationDao;
import org.apache.hadoop.hbase.client.Put;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Liuq{

    /**
     *
     */
   public static void main(String[] args){


       String driver = "com.mysql.jdbc.Driver";
       String url = "jdbc:mysql://localhost:3306/hbasedemo";
       String username = "qiang";
       String password = "123456";
       Connection conn = null;//连接对象
       PreparedStatement pstmt=null;//ps对象
       ResultSet rs=null;
       try {
           Class.forName(driver); //classLoader,加载对应驱动
           conn = (Connection) DriverManager.getConnection(url, username, password);
           String sql = "select * from transfer_task_to";
           pstmt = (PreparedStatement)conn.prepareStatement(sql);
           rs= pstmt.executeQuery();
           List<Put> list=new ArrayList();

           while (rs.next()) {

               String id=rs.getString(1);
               String already_retry=rs.getString(2);
               String task_id=rs.getString(3);
               Date create_time=rs.getDate(4);
               String exception_number=rs.getString(5);
               String status=rs.getString(6);
               String read_number=rs.getString(7);
               String fail_number=rs.getString(8);
               String write_number=rs.getString(9);
               String plan_id=rs.getString(10);
               Date start_time=rs.getDate(11);
               String in_filter_number=rs.getString(12);
               String out_filter_number=rs.getString(13);
               String from_run_param=rs.getString(14);
               String current_retry_times=rs.getString(15);
               String worker_name=rs.getString(16);
               String retry_flag=rs.getString(17);
               String parent_task_id=rs.getString(18);
               Date end_time=rs.getDate(19);
               Date kill_time=rs.getDate(20);
               Date failure_time=rs.getDate(21);
               Date overtime_time=rs.getDate(22);
               String to_run_param=rs.getString(23);
               String ins_id=rs.getString(24);
               String exception_info=rs.getString(25);

               Put put=new Put(id.getBytes());
               put.addColumn("F1".getBytes(), "task_id".getBytes(), (task_id!=null?task_id:"").getBytes());
               put.addColumn("F1".getBytes(), "id".getBytes(), (id!=null?id:"").getBytes());
               put.addColumn("F1".getBytes(), "create_time".getBytes(), (create_time!=null?end_time.toString():"").getBytes());
               put.addColumn("F1".getBytes(), "start_time".getBytes(), (start_time!=null?end_time.toString():"").getBytes());
               put.addColumn("F1".getBytes(), "out_filter_number".getBytes(), (out_filter_number!=null?out_filter_number:"").getBytes());
               put.addColumn("F1".getBytes(), "from_run_param".getBytes(), (from_run_param!=null?from_run_param:"").getBytes());
               put.addColumn("F2".getBytes(), "current_retry_times".getBytes(), (current_retry_times!=null?end_time.toString():"").getBytes());
               put.addColumn("F2".getBytes(), "retry_flag".getBytes(), (retry_flag!=null?retry_flag:"").getBytes());
               put.addColumn("F2".getBytes(), "parent_task_id".getBytes(), (parent_task_id!=null?parent_task_id:"").getBytes());
               put.addColumn("F2".getBytes(), "end_time".getBytes(), (end_time!=null?end_time.toString():"").getBytes());
               put.addColumn("F2".getBytes(), "kill_time".getBytes(), (kill_time!=null?end_time.toString():"").getBytes());
               put.addColumn("F2".getBytes(), "failure_time".getBytes(), (failure_time!=null?end_time.toString():"").getBytes());

               list.add(put);
           }
           HBaseOperationDao.putList("BD_TEST",list);
       } catch (ClassNotFoundException e) {
           e.printStackTrace();
       } catch (SQLException e) {
           e.printStackTrace();
       }finally {
           try {
               if(rs!=null)rs.close();
               if(pstmt!=null)rs.close();
               if(conn!=null)rs.close();
           }catch (Exception e){

           }
       }
   }

}